package com.das.mechanic_base.widget;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;

import com.das.mechanic_base.R;
import com.das.mechanic_base.base.X3BaseSelfBottomSheetDialog;
import com.das.mechanic_base.utils.X3ScreenUtils;
import com.umeng.analytics.MobclickAgent;
import com.zyyoona7.wheel.WheelView;

import java.util.List;

public class X3BottomPrecentPickerDialog extends X3BaseSelfBottomSheetDialog implements View.OnClickListener {

    private WheelView<String> wv_view;

    private TextView tv_num_picker;

    private int startIndex = 0;

    private String selectData = "0";
    private Button btn_cancel;
    private Button btn_affirm;

    public X3BottomPrecentPickerDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        wv_view = findViewById(R.id.wv_view);
        tv_num_picker = findViewById(R.id.tv_num_picker);
        btn_cancel = findViewById(R.id.btn_cancel);
        btn_affirm = findViewById(R.id.btn_affirm);

        btn_affirm.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_number_percent_picker;
    }

    @Override
    protected int getDialogHeight() {
        return X3ScreenUtils.getScreenHeight(mContext) / 2;
    }

    public void showContent(String startData, List<String> dataList, String title) {
        this.selectData = startData;
        tv_num_picker.setText(title);
        for (int i = 0; i < dataList.size(); i++) {
            if (dataList.get(i).equals(startData)) {
                startIndex = i;
            }
        }
        wv_view.setData(dataList);
        wv_view.setTypeface(ResourcesCompat.getFont(mContext,R.font.din_text_type));
        wv_view.setSelectedItemPosition(startIndex);
        wv_view.setSoundEffectResource(R.raw.x3_button_choose);
        wv_view.setSoundEffect(true);
        wv_view.setPlayVolume(0.5f);
        wv_view.setOnItemSelectedListener((wheelView, data, position) -> selectData = data);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.btn_affirm) {
            dismiss();
            if (iOnItemCameraClick != null) {
                iOnItemCameraClick.iOpenAffirmListener(wv_view.getSelectedItemData());
            }
        } else if (id == R.id.btn_cancel) {
            dismiss();
            if (iOnItemCameraClick != null) {
                iOnItemCameraClick.iOpenCancelListener();
            }
        }
    }

    IOpenNumberClick iOnItemCameraClick;

    public void setiOnItemCameraClick(IOpenNumberClick iOnItemCameraClick) {
        this.iOnItemCameraClick = iOnItemCameraClick;
    }

    public interface IOpenNumberClick {

        void iOpenCancelListener();

        void iOpenAffirmListener(String selectData);

    }

    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("初检信息进厂油量弹窗");
    }

    @Override
    protected void onStop() {
        super.onStop();
        MobclickAgent.onPageEnd("初检信息进厂油量弹窗");
    }
}
